package com.xh.bussiness.thirdapi;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.StringUtil;
import com.xh.bussiness.longwen.bean.dto.AreaDto;
import com.xh.bussiness.longwen.bean.dto.TeacherPaikeDto;
import com.xh.bussiness.longwen.bean.request.QueryTeacherPaikeRequest;
import com.xh.core.bean.XhPage;
import com.xh.core.properties.XhProperties;
import org.apache.commons.collections4.MapUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 龙文业务系统接口
 * </p>
 *
 * @author Pitt zhang
 * @since 2019/10/16
 */
@Component
public class LongwenApi {

    public static final Logger logger = LoggerFactory.getLogger(LongwenApi.class);

    public static String longwenApiHost;

    /**
     * 注入静态 longwenApiHost
     *
     * @param xhProperties
     */
    @Resource(name = "xhProperties")
    public void setLongwenApiHost(XhProperties xhProperties) {
        LongwenApi.longwenApiHost = xhProperties.getLongwenApiHost();
    }


    /**
     * 查询教师排课信息
     *
     * @param page
     * @param request
     * @return
     */
    public static XhPage<TeacherPaikeDto> queryTeacherPaikeList(XhPage page, QueryTeacherPaikeRequest request) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryTeacherPaikeList?teacherId=" + request.getTeacherId() + "&current=" + page.getCurrent() + "&size=" + page.getSize();
            if (!StringUtils.isEmpty(request.getStartTime())) {
                url += "&startTime=" + request.getStartTime();
            }
            if (!StringUtils.isEmpty(request.getEndTime())) {
                url += "&endTime=" + request.getEndTime();
            }
            if (request.getClassType() != null) {
                url += "&classType=" + request.getClassType();
            }
            if (request.getSchoolId() != null) {
                url += "&schoolId=" + request.getSchoolId();
            }
            if (!StringUtils.isEmpty(request.getSchoolTime())) {
                url += "&schoolTime=" + request.getSchoolTime();
            }
            JSONObject jsonObject = executeGetHttp(url);

            List<TeacherPaikeDto> resultList = new ArrayList<>();
            JSONObject jsonObj = (JSONObject) jsonObject.get("json");
            List records = (List) jsonObj.get("records");
            if (!CollectionUtils.isEmpty(records)) {
                for (Object item : records) {
                    JSONObject obj = (JSONObject) item;
                    TeacherPaikeDto teacherPaikeDto = JSON.parseObject(JSON.toJSONString(obj), TeacherPaikeDto.class);
                    resultList.add(teacherPaikeDto);
                }
                page.setRecords(resultList);
            }
            Object total = jsonObj.get("total");
            if (total != null) {
                page.setTotal(StringUtils.isEmpty(total.toString()) ? 0 : Integer.parseInt(total.toString()));
            }
        } catch (Exception e) {
            logger.error(String.format("queryTeacherPaikeList have error: %s", e.getMessage()));
        }
        return page;
    }

    /**
     * 根据老师和校区查询一对一学生
     *
     * @param pageNo
     * @param pageSize
     * @param request
     * @return
     */
    public static XhPage<Map<String, Object>> queryTeacherOneByOneStudents(Long pageNo, Long pageSize, QueryTeacherPaikeRequest request) {
        XhPage page = new XhPage();
        page.setCurrent(pageNo);
        page.setSize(pageSize);
        try {
            String url = longwenApiHost + "/lwthird/api/queryTeacherOneByOneStudents?teacherId=" + request.getTeacherId() + "&current=" + page.getCurrent() + "&size=" + page.getSize();
            if (request.getSchoolId() != null) {
                url += "&schoolId=" + request.getSchoolId();
            }
            JSONObject jsonObject = executeGetHttp(url);

            JSONObject jsonObj = (JSONObject) jsonObject.get("json");
            List records = (List) jsonObj.get("records");
            page.setRecords(records);
            Object total = jsonObj.get("total");
            if (total != null) {
                page.setTotal(StringUtils.isEmpty(total.toString()) ? 0 : Integer.parseInt(total.toString()));
            }
        } catch (Exception e) {
            logger.error(String.format("queryTeacherOneByOneStudents have error: %s", e.getMessage()));
        }
        return page;
    }

    /**
     * 查询老师拥有的班课
     *
     * @param pageNo
     * @param pageSize
     * @param request
     * @return
     */
    public static XhPage<Map<String, Object>> queryTeacherXiaoban(Long pageNo, Long pageSize, QueryTeacherPaikeRequest request) {
        XhPage page = new XhPage();
        page.setCurrent(pageNo);
        page.setSize(pageSize);
        try {
            String url = longwenApiHost + "/lwthird/api/queryTeacherXiaoban?teacherId=" + request.getTeacherId() + "&current=" + page.getCurrent() + "&size=" + page.getSize();
            if (request.getSchoolId() != null) {
                url += "&schoolId=" + request.getSchoolId();
            }
            JSONObject jsonObject = executeGetHttp(url);

            JSONObject jsonObj = (JSONObject) jsonObject.get("json");
            List records = (List) jsonObj.get("records");
            page.setRecords(records);
            Object total = jsonObj.get("total");
            if (total != null) {
                page.setTotal(StringUtils.isEmpty(total.toString()) ? 0 : Integer.parseInt(total.toString()));
            }
        } catch (Exception e) {
            logger.error(String.format("queryTeacherXiaoban have error: %s", e.getMessage()));
        }
        return page;
    }

    /**
     * 通过身份证查询龙文系统中的用户信息
     *
     * @param idCard
     * @return
     */
    public static List<Map<String, Object>> queryUserByIdCardAndMobile(String idCard, String mobile) {
        try {
            if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(mobile)) {
                return new ArrayList<>();
            }
            String url = longwenApiHost + "/lwthird/api/queryUserByIdCardAndMobile?idCard=" + idCard + "&mobile=" + mobile;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryUserByIdCard(%s) result is null", idCard));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryUserByIdCard have error: %s", e.getMessage()));
        }
        return null;
    }

    /**
     * 通过身份证查询龙文系统中的老师信息
     *
     * @param idCard
     * @return
     */
    public static List<Map<String, Object>> queryTeacherByIdCardAndMobile(String idCard, String mobile) {
        try {
            if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(mobile)) {
                return new ArrayList<>();
            }
            String url = longwenApiHost + "/lwthird/api/queryTeacherByIdCardAndMobile?idCard=" + idCard + "&mobile=" + mobile;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryTeacherByIdCard(%s) result is null", idCard));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryTeacherByIdCard have error: %s", e.getMessage()));
        }
        return null;
    }

    /**
     * 查询一对一学生合同
     *
     * @param studentId
     * @return
     */
    public static Object queryStudentOneByOneContract(Integer studentId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryStudentOneByOneContract?studentId=" + studentId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            return object;
        } catch (Exception e) {
            logger.error(String.format("queryStudentOneByOneContract have error: %s", e.getMessage()));
        }
        return null;
    }


    /**
     * 小班查询学生信息
     *
     * @return
     */
    public static Object queryStudentInfoByContractId(Integer contractId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryStudentInfoByContractId?contractId=" + contractId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            return object;
        } catch (Exception e) {
            logger.error(String.format("queryStudentInfoByContractId have error: %s", e.getMessage()));
        }
        return null;
    }


    /**
     * 小班查询学生信息
     *
     * @return
     */
    public static Object queryStudentByClassId(Integer classId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryStudentByClassId?classId=" + classId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            return object;
        } catch (Exception e) {
            logger.error(String.format("queryStudentByClassId have error: %s", e.getMessage()));
        }
        return null;
    }

    /**
     * 根据家长手机号查询学生
     *
     * @param mobile
     * @return
     */
    public static List<Map<String, Object>> queryStudentByParentMobile(String mobile) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryStudentByParentMobile?mobile=" + mobile;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryStudentByParentMobile(%s) result is null", mobile));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryStudentByParentMobile have error: %s", e.getMessage()));
        }
        return null;
    }

    /**
     * 根据手机号查询教师数据
     *
     * @param mobile
     * @return
     */
    public static List<Map<String, Object>> queryTeacherByMobile(String mobile) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryTeacherByMobile?mobile=" + mobile;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryTeacherByMobile(%s) result is null", mobile));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryTeacherByMobile have error: %s", e.getMessage()));
        }
        return null;
    }

    /**
     * 根据手机号查询用户数据
     *
     * @param mobile
     * @return
     */
    public static List<Map<String, Object>> queryPersonnelByIdMobile(String mobile) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryPersonnelByIdMobile?mobile=" + mobile;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryPersonnelByIdMobile(%s) result is null", mobile));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryPersonnelByIdMobile have error: %s", e.getMessage()));
        }
        return null;
    }

    public static List<Map<String, Object>> queryStudentIdsByParentMobile(String mobile) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryStudentIdsByParentMobile?mobile=" + mobile;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryStudentIdsByParentMobile(%s) result is null", mobile));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryStudentIdsByParentMobile have error: %s", e.getMessage()));
        }
        return null;
    }

    public static List<Map<String, Object>> queryTeacherIdsByMobile(String mobile) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryTeacherIdsByMobile?mobile=" + mobile;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryTeacherIdsByMobile(%s) result is null", mobile));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryTeacherIdsByMobile have error: %s", e.getMessage()));
        }
        return null;
    }

    public static List<Map<String, Object>> queryPersonnelIdsByIdMobile(String mobile) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryPersonnelIdsByIdMobile?mobile=" + mobile;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryPersonnelIdsByIdMobile(%s) result is null", mobile));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryPersonnelIdsByIdMobile have error: %s", e.getMessage()));
        }
        return null;
    }

    /**
     * 根据龙文教师id查询一对一和小班学生
     *
     * @param lwTeacherId
     * @return
     */
    public static List<Map<String, Object>> queryAllStudentByTeacherId(String lwTeacherId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryAllStudentByTeacherId?teacherId=" + lwTeacherId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryAllStudentByTeacherId(%s) result is null", lwTeacherId));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryAllStudentByTeacherId have error: %s", e.getMessage()));
        }
        return null;
    }

    /**
     * 根据学生id查询所在班级id
     *
     * @param lwStudentId
     * @return
     */
    public static List<String> queryClassIdsByStuId(String lwStudentId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryClassIdsByStuId?studentId=" + lwStudentId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<String> resultList = (List<String>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryClassIdsByStuId(%s) result is null", lwStudentId));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryClassIdsByStuId have error: %s", e.getMessage()));
        }
        return new ArrayList<>();
    }

    /**
     * 查询学生剩余课时
     *
     * @param lwStudentId
     * @return
     */
    public static Map<String, Object> queryStudentRemainContractNumber(String lwStudentId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryStudentRemainContractNumber?studentId=" + lwStudentId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                Map<String, Object> result = (Map<String, Object>) object;

                if (MapUtils.isEmpty(result)) {
                    logger.warn(String.format("queryStudentRemainContractNumber(%s) result is null", lwStudentId));
                }
                return result;
            }
        } catch (Exception e) {
            logger.error(String.format("queryStudentRemainContractNumber have error: %s", e.getMessage()));
        }
        return new HashMap<>();
    }

    /**
     * 查询学生排课记录
     *
     * @param page
     * @param request
     * @return
     */
    public static XhPage<TeacherPaikeDto> queryStudentPaikeList(XhPage page, QueryTeacherPaikeRequest request) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryStudentPaikeList?studentId=" + request.getLwStudentId() + "&current=" + page.getCurrent() + "&size=" + page.getSize();
            JSONObject jsonObject = executeGetHttp(url);

            List<TeacherPaikeDto> resultList = new ArrayList<>();
            JSONObject jsonObj = (JSONObject) jsonObject.get("json");
            List records = (List) jsonObj.get("records");
            if (!CollectionUtils.isEmpty(records)) {
                for (Object item : records) {
                    JSONObject obj = (JSONObject) item;
                    TeacherPaikeDto teacherPaikeDto = JSON.parseObject(JSON.toJSONString(obj), TeacherPaikeDto.class);
                    resultList.add(teacherPaikeDto);
                }
                page.setRecords(resultList);
            }
            Object total = jsonObj.get("total");
            if (total != null) {
                page.setTotal(StringUtils.isEmpty(total.toString()) ? 0 : Integer.parseInt(total.toString()));
            }
        } catch (Exception e) {
            logger.error(String.format("queryStudentPaikeList have error: %s", e.getMessage()));
        }
        return page;
    }


    /**
     * 根据龙文业务系统学生id获取学生信息
     *
     * @param lwStudentId
     * @return
     */
    public static Map<String, Object> queryStudentInfoById(String lwStudentId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryStudentInfoById?studentId=" + lwStudentId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                Map<String, Object> result = (Map<String, Object>) object;

                if (MapUtils.isEmpty(result)) {
                    logger.warn(String.format("queryStudentInfoById(%s) result is null", lwStudentId));
                }
                return result;
            }
        } catch (Exception e) {
            logger.error(String.format("queryStudentInfoById have error: %s", e.getMessage()));
        }
        return new HashMap<>();
    }

    /**
     * 根据班级id查询学生
     *
     * @param classId
     * @return
     */
    public static List<Map<String, Object>> queryClassStudentByClasId(String classId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryClassStudentByClasId?classId=" + classId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                if (CollectionUtils.isEmpty(resultList)) {
                    logger.warn(String.format("queryClassStudentByClasId(%s) result is null", classId));
                }
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryClassStudentByClasId have error: %s", e.getMessage()));
        }
        return null;
    }

    /**
     * 查询教师排课日历
     *
     * @param request
     * @return
     */
    public static List<Map<String, Object>> queryTeacherPaikeCalendar(QueryTeacherPaikeRequest request) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryTeacherPaikeCalendar?teacherId=" + request.getTeacherId();
            if (!StringUtils.isEmpty(request.getStartTime())) {
                url += "&startTime=" + request.getStartTime();
            }
            if (!StringUtils.isEmpty(request.getEndTime())) {
                url += "&endTime=" + request.getEndTime();
            }
            if (request.getSchoolId() != null) {
                url += "&schoolId=" + request.getSchoolId();
            }
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryTeacherPaikeCalendar have error: %s", e.getMessage()));
        }
        return null;
    }

    /**
     * 根据龙文校区查询教师数据
     *
     * @return
     */
    public static XhPage<Map<String, Object>> queryTeacherBySchoolId(XhPage page, Integer schoolId) {
        if (schoolId == null) {
            return page;
        }
        try {
            String url = longwenApiHost + "/lwthird/api/queryTeacherBySchoolId?schoolId=" + schoolId + "&current=" + page.getCurrent() + "&size=" + page.getSize();
            JSONObject jsonObject = executeGetHttp(url);

            JSONObject jsonObj = (JSONObject) jsonObject.get("json");
            List records = (List) jsonObj.get("records");
            page.setRecords(records);
            Object total = jsonObj.get("total");
            if (total != null) {
                page.setTotal(StringUtils.isEmpty(total.toString()) ? 0 : Integer.parseInt(total.toString()));
            }
        } catch (Exception e) {
            logger.error(String.format("queryTeacherXiaoban have error: %s", e.getMessage()));
        }
        return page;
    }


    public static String queryUserAndTeacherRoleId(String lwUserId, String lwSchoolId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryUserAndTeacherRoleId?userId=" + lwUserId + "&lwSchoolId=" + lwSchoolId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                return object.toString();
            }
        } catch (Exception e) {
            logger.error(String.format("queryClassIdsByStuId have error: %s", e.getMessage()));
        }
        return null;
    }

    /**
     * 根据区域id查询校区
     *
     * @param areaId
     * @return
     */
    public static Map<String, Object> querySchoolByAreaId(Integer areaId) {
        try {
            String url = longwenApiHost + "/lwthird/api/querySchoolByAreaId?areaId=" + areaId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                Map<String, Object> result = (Map<String, Object>) object;

                if (MapUtils.isEmpty(result)) {
                    logger.warn(String.format("querySchoolByAreaId(%s) result is null", areaId));
                }
                return result;
            }
        } catch (Exception e) {
            logger.error(String.format("querySchoolByAreaId have error: %s", e.getMessage()));
        }
        return new HashMap<>();
    }

    private static JSONObject executeGetHttp(String url) {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpGet get = new HttpGet(url);
        //执行请求
        HttpResponse response = null;
        try {
            response = httpclient.execute(get);
            String responseEntity = EntityUtils.toString(response.getEntity(), "utf-8");
            if (!StringUtil.isEmpty(responseEntity)) {
                //判断是否发送成功，发送成功返回true
                JSONObject result = JSON.parseObject(responseEntity);
                return result;
            }
        } catch (Exception e) {
            try {
                e.printStackTrace();
                ((CloseableHttpResponse) response).close();
                httpclient.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 根据龙文业务系统学生id获取学生信息
     *
     * @param lwStudentId
     * @return
     */
    public static Map<String, Object> queryStudentNameById(String lwStudentId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryStudentNameById?stuId=" + lwStudentId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                Map<String, Object> result = (Map<String, Object>) object;

                if (MapUtils.isEmpty(result)) {
                    logger.warn(String.format("queryStudentNameById(%s) result is null", lwStudentId));
                }
                return result;
            }
        } catch (Exception e) {
            logger.error(String.format("queryStudentNameById have error: %s", e.getMessage()));
        }
        return new HashMap<>();
    }

    /**
     * 查询地区、校区数据
     * @param parentId
     * @return
     */
    public static List<Map<String, Object>> queryAreaByParentId(Integer parentId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryAreaByParentId";
            if (parentId != null) {
                url += "?parentId=" + parentId;
            }
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                List<Map<String, Object>> resultList = (List<Map<String, Object>>) object;
                return resultList;
            }
        } catch (Exception e) {
            logger.error(String.format("queryAreaByParentId have error: %s", e.getMessage()));
        }
        return  null;
    }

    /**
     * 获取地区数据
     * @param areaId
     * @return
     */
    public static AreaDto queryAreaBySchoolId(Integer schoolId) {
        try {
            String url = longwenApiHost + "/lwthird/api/queryAreaBySchoolId?schoolId=" + schoolId;
            JSONObject jsonObject = executeGetHttp(url);
            Object object = jsonObject.get("json");
            if (object != null) {
                AreaDto areaDto = JSON.parseObject(JSON.toJSONString(object), AreaDto.class);
                return areaDto;
            }
        } catch (Exception e) {
            logger.error(String.format("queryAreaBySchoolId have error: %s", e.getMessage()));
        }
        return  null;
    }
}